import { PlayerMiniInfo } from "../../../model/PlayerMiniInfo";
import { DataProvider } from "../../../../../fl/data/DataProvider";
import { FriendInfo } from "../../../model/FriendInfo";
import { PlayerOpMenuConst } from "./PlayerOpMenuConst";
import { Global } from "../../../../../com/gengine/global/Global";
import { LayerManager } from "../../../manager/LayerManager";
import { ListMenu } from "./ListMenu";
import { PlayerMenuCellRenderer } from "./PlayerMenuCellRenderer";
import { ListEvent } from "../../../../../fl/events/ListEvent";
//class PlayerOpRegister
    
    export  class PlayerOpRegister
    {
        

        public static Register(arg1: Object /* flash.display.InteractiveObject */, arg2: PlayerMiniInfo, arg3: DataProvider=null, arg4: FriendInfo=null): void
        {
            if (!PlayerOpRegister.HasRegister(arg1)) 
            {
                if (!arg3) 
                {
                    arg3 = PlayerOpMenuConst.ChatOpMenu;
                }
                if (arg3.length == 0) 
                {
                    return;
                }
                PlayerOpRegister._dicObjInfo[arg1] = arg2;
                PlayerOpRegister._dicObjFriendInfo[arg1] = arg4;
                PlayerOpRegister._dicObjdata[arg1] = arg3;
                arg1.addEventListener(flash.events.MouseEvent.CLICK, PlayerOpRegister.showInfo, false, 0);
                Global.stage.addEventListener(flash.events.MouseEvent.CLICK, PlayerOpRegister.HideHandler);
            }
            return;
        }

        public static UnRegister(arg1: Object /* flash.display.InteractiveObject */): void
        {
            arg1.removeEventListener(flash.events.MouseEvent.CLICK, PlayerOpRegister.showInfo);
            delete PlayerOpRegister._dicObjInfo[arg1];
            delete PlayerOpRegister._dicObjdata[arg1];
            delete PlayerOpRegister._dicObjFriendInfo[arg1];
            return;
        }

        public static ShowOpList(arg1: PlayerMiniInfo, arg2: number, arg3: number, arg4: DataProvider=null): void
        {
            if (!arg4) 
            {
                arg4 = PlayerOpMenuConst.ChatOpMenu;
            }
            if (!PlayerOpRegister._layer) 
            {
                PlayerOpRegister._layer = LayerManager.topLayer;
            }
            PlayerOpRegister.createPlayerOpList();
            PlayerOpRegister._currentPlayerMiniInfo = arg1;
            PlayerOpRegister._currentFriendMiniInfo = null;
            PlayerOpRegister._layer.addChild(PlayerOpRegister._playerOpList);
            PlayerOpRegister._playerOpList.dataProvider = PlayerOpMenuConst.getEnabeldAttri(arg4, arg1);
            arg2 = arg2 < PlayerOpRegister._layer.stage.stageWidth - PlayerOpRegister._playerOpList.width ? arg2 : arg2 - PlayerOpRegister._playerOpList.width;
            arg3 = arg3 < PlayerOpRegister._layer.stage.stageHeight - PlayerOpRegister._playerOpList.height ? arg3 : arg3 - PlayerOpRegister._playerOpList.height;
            PlayerOpRegister._playerOpList.show(arg2, arg3, PlayerOpRegister._layer);
            return;
        }

        public static HasRegister(arg1: Object /* flash.display.InteractiveObject */): Boolean
        {
            return PlayerOpRegister._dicObjInfo.hasOwnProperty(arg1) ? true : false;
        }

        public static HideOpList(): void
        {
            if (PlayerOpRegister._playerOpList) 
            {
                PlayerOpRegister._playerOpList.hide();
            }
            return;
        }

        /* internal  */static createPlayerOpList(): void
        {
            if (!PlayerOpRegister._playerOpList) 
            {
                PlayerOpRegister._playerOpList = new ListMenu();
                PlayerOpRegister._playerOpList.width = 86;
                PlayerOpRegister._playerOpList.visible = false;
                PlayerOpRegister._playerOpList.list.setStyle("cellRenderer", PlayerMenuCellRenderer);
                PlayerOpRegister._playerOpList.list.drawNow();
                PlayerOpRegister._playerOpList.list.addEventListener(ListEvent.ITEM_CLICK, PlayerOpRegister.PlayerOpItemSelect);
            }
            return;
        }

        /* internal  */static showInfo(arg1: Object /* flash.events.MouseEvent */): void
        {
            var loc1=NaN;
            var loc2=NaN;
            if (!PlayerOpRegister._layer) 
            {
                PlayerOpRegister._layer = LayerManager.topLayer;
            }
            PlayerOpRegister.createPlayerOpList();
            PlayerOpRegister._currnetActiveObject = arg1.currentTarget as Object /* flash.display.InteractiveObject */;
            PlayerOpRegister._currentPlayerMiniInfo = PlayerOpRegister._dicObjInfo[PlayerOpRegister._currnetActiveObject];
            PlayerOpRegister._currentFriendMiniInfo = PlayerOpRegister._dicObjFriendInfo[PlayerOpRegister._currnetActiveObject];
            if (PlayerOpRegister._currnetActiveObject.parent) 
            {
                PlayerOpRegister._layer.addChild(PlayerOpRegister._playerOpList);
                PlayerOpRegister._playerOpList.dataProvider = PlayerOpMenuConst.getEnabeldAttri(PlayerOpRegister._dicObjdata[PlayerOpRegister._currnetActiveObject], PlayerOpRegister._dicObjInfo[PlayerOpRegister._currnetActiveObject]);
                loc1 = arg1.stageX;
                loc2 = arg1.stageY;
                loc1 = loc1 < PlayerOpRegister._layer.stage.stageWidth - PlayerOpRegister._playerOpList.width ? loc1 : loc1 - PlayerOpRegister._playerOpList.width;
                loc2 = loc2 < PlayerOpRegister._layer.stage.stageHeight - PlayerOpRegister._playerOpList.height ? loc2 : loc2 - PlayerOpRegister._playerOpList.height;
                PlayerOpRegister._playerOpList.show(loc1, loc2, PlayerOpRegister._layer);
            }
            arg1.stopImmediatePropagation();
            return;
        }

        /* internal  */static HideHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            PlayerOpRegister.HideOpList();
            return;
        }

        /* internal  */static PlayerOpItemSelect(arg1: ListEvent): void
        {
            PlayerOpMenuConst.Opearte(PlayerOpRegister._playerOpList.list.dataProvider.getItemAt(arg1.index)["label"], PlayerOpRegister._currentPlayerMiniInfo, PlayerOpRegister._currentFriendMiniInfo);
            return;
        }

        /* internal */ static /* var */_playerOpList: ListMenu;

        /* internal */ static /* var */_layer: Object /* flash.display.Sprite */;

        /* internal */ static /* var */_currnetActiveObject: Object /* flash.display.InteractiveObject */;

        /* internal */ static /* var */_currentPlayerMiniInfo: PlayerMiniInfo=null;

        /* internal */ static /* var */_currentFriendMiniInfo: FriendInfo=null;

        /* internal */ static /* var */_dicObjInfo: Map<any, any> /* flash.utils.Dictionary */;

        /* internal */ static /* var */_dicObjdata: Map<any, any> /* flash.utils.Dictionary */;

        /* internal */ static /* var */_dicObjFriendInfo: Map<any, any> /* flash.utils.Dictionary */;
    }

            PlayerOpRegister._currentPlayerMiniInfo = null;
            PlayerOpRegister._currentFriendMiniInfo = null;
            PlayerOpRegister._dicObjInfo = new Map<any, any> /* flash.utils.Dictionary */(true);
            PlayerOpRegister._dicObjdata = new Map<any, any> /* flash.utils.Dictionary */(true);
            PlayerOpRegister._dicObjFriendInfo = new Map<any, any> /* flash.utils.Dictionary */(true);
        